package com.zkc.blog.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkc.blog.mapper.CommentMapper;
import com.zkc.blog.pojo.Comment;
import com.zkc.blog.pojo.CommentExample;
import com.zkc.blog.service.CommentService;

@Service
public class CommentServiceImpl implements CommentService {

	@Autowired
	private CommentMapper commentMapper;
	
	@Override
	public void insertComment(Comment comment) {
		// TODO Auto-generated method stub
		commentMapper.insert(comment);
	}

	@Override
	public void deleteCommentById(List<Integer> ids) throws Exception {
		if(ids==null || ids.size()<=0){
			throw new Exception("空id");
		}
		CommentExample ex=new CommentExample();
		ex.createCriteria().andCommentidIn(ids);
		commentMapper.deleteByExample(ex);
	}

	@Override
	public List<Comment> getCommentList(String searchkey,Integer blogid) {
		// TODO Auto-generated method stub
		if(searchkey==null){
			searchkey="";
		}
		searchkey="%"+searchkey+"%";
		CommentExample ex=new CommentExample();
		if(blogid!=null && blogid>-1){
			ex.createCriteria().andContentLike(searchkey).andBlogidEqualTo(blogid);
		}else{
			ex.createCriteria().andContentLike(searchkey);
		}
		commentMapper.selectByExample(ex);
		return commentMapper.selectByExample(ex);
	}

	@Override
	public Comment getCommentById(Integer id) {
		// TODO Auto-generated method stub
		return commentMapper.selectById(id);
	}

}
